<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            文件列表
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

        <ul class="ui-selectee" id="tbodyHtml">

        </ul>
    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    var uiMediaScanner = null;
    var imageFilter = null;
    var imageBrowser = null;
    apiready = function () {
        var list = api.pageParam.list;

        setTable(list) 


    }

/*     //文件
    function goDetailBHPge(ext09) {
        var ext09 = ext09
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/fileInfoGet";
        var data = {
            values: {
                ext09: ext09,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0' && myobj.list.length > 0) {
                    var list = eval(myobj.list);
                    setTable(list)
                   // console.log(list[0].docid,list[0].file_name)
                    //console.log(list[0].docid,list[0].file_original_name)
                    //openFile(list[0].docid,list[0].file_original_name)
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    } */
    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            html += "<div style='padding-top:4%;'></div>";
            html += "<li class='sortable ui-selectee ui-sortable' >";
            html += "<ul class='aui-list aui-media-list ui-selectee'   >";
            html += "<li class='aui-list-item  ui-selectee'>";
            html += "<div class='aui-media-list-item-inner ui-selectee' onclick='openFile(\"" + list[i].docid + "\",\"" + list[i].file_name + "\");'>";
            html += "<div class='aui-list-item-inner ui-selectee' style='background-color:#cbf9cc;margin-right:15px'>";
            html += "<div class='aui-list-item-text ui-selectee' style='line-height: 20px;text-align:center' >";
            html += "<div class='aui-list-item-inner ui-selectee' style='color:#000000;'>" + list[i].file_original_name + "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };
    //文件预览
    function openFile(docId, fileName) {
        var serverUrl = localStorage.getItem('serverUrl');
        var downloadUrl = serverUrl + `/app/openFile/` + docId;
        var un = localStorage.getItem('un');
        var data = {
            values: {
                un:un
            }
        }
        api.download({
            url: downloadUrl,
            report: true,
            savePath: 'fs://' + fileName,
            data:data
        }, function (ret, err) {
   
            if (ret && 1 == ret.state) { /* 下载完成 */
                //console.log("下载成功savePath:" + ret.savePath);
                // 打开文件
                var docReader = api.require('docReader');
                docReader.open({
                    path: 'fs://' + fileName
                }, function (ret, err) {
                    if (ret.status) {
                        console.log("文件打开成功：" + ret);
                    } else {
                        alert(JSON.stringify(err));
                    }
                });
            }

            if (ret && 2 == ret.state) {
                console.log("下载失败");
            }
        });
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>